package com.tanhua.server.controller;

import com.tanhua.server.service.IMService;
import com.tanhua.server.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("messages")
@Slf4j
public class IMController {
    
    @Autowired
    private UserService userService;
    @Autowired
    private IMService imService;
    
    /**
     * 接口名称：根据环信id查询用户信息
     * 接口路径：GET/messages/userinfo
     * 请求参数：huanxinId
     */
    @GetMapping("userinfo")
    public ResponseEntity<Object> queryUserInfoByUserId(Long huanxinId) {
        return userService.findUserInfoById(null, huanxinId);
    }
    
    /**
     * 接口名称：联系人添加
     * 接口路径：POST/messages/contacts
     */
    @PostMapping("contacts")
    public ResponseEntity<Object> addContacts(
            @RequestBody Map<String, Long> map) {
        log.info("接口名称：联系人添加");
        Long friendId = map.get("userId");
        return imService.addContacts(friendId);
    }
    
    /**
     * 接口名称：联系人列表
     * 接口路径：GET/messages/contacts
     */
    @GetMapping("contacts")
    public ResponseEntity<Object> contactsList(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize, String keyword) {
        return imService.contactsList(page, pagesize, keyword);
    }
    
    /**
     * 接口名称：点赞列表（属于消息通知）
     * 接口路径：GET /messages/likes
     */
    
    @GetMapping("likes")
    public ResponseEntity<Object> likes(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize) {
        return imService.likes(page, pagesize);
    }
    
    /**
     * 接口名称：（文字）评论列表（属于消息通知）
     * 接口路径：GET /messages/likes
     */
    
    @GetMapping("comments")
    public ResponseEntity<Object> comments(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize) {
        return imService.comments(page, pagesize);
    }
    
    /**
     * 接口名称：喜欢列表（属于消息通知）
     * 接口路径：GET /messages/likes
     */
    
    @GetMapping("loves")
    public ResponseEntity<Object> loves(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize) {
        return imService.loves(page, pagesize);
    }
    
}